package invoice;

import invoice.header.Header;
import invoice.line.Line;

public class Controller {
    public void setAndPrintInvoice(Header[] header,Line[] line){
        HeaderAndFooterList hf=new HeaderAndFooterList();
        LineList ll=new LineList();
        hf.add(header);
        hf.decorate();
        ll.add(line);
        ll.decorate();
        printInvoice(hf,ll);
    }

    private void printBlank(){
        for(int i=0;i<56;i++)
            System.out.print("=");
        System.out.println();
    }

    private String changeLength(String str){
        StringBuilder sb=new StringBuilder(str);
        for(int i=sb.length();i<15;i++){
            sb.append(" ");
        }
        return sb.toString();
    }

    private void printWords(){
        System.out.print("No."+changeLength("Item")+
                changeLength("Units")+
                changeLength("Unit Price")+
                changeLength("Subtotal"));
        System.out.println();
    }

    private void printInvoice(HeaderAndFooterList hf,LineList ll){
        hf.printHeader();
        printBlank();
        printWords();
        ll.print();
        printBlank();
        hf.printFooter();
    }
}
